﻿package mortal.game.scene3D.layer3D
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.player.item.*;

    public class DropItemDictionary extends Object
    {
        private var _map:Dictionary;

        public function DropItemDictionary(param1:Boolean = false)
        {
            this._map = new Dictionary(param1);
            return;
        }// end function

        public function addDropItem(param1:SEntityId, param2:ItemPlayer) : ItemPlayer
        {
            this._map[EntityUtil.toString(param1)] = param2;
            return param2;
        }// end function

        public function removeDropItem(param1:SEntityId) : ItemPlayer
        {
            var _loc_2:* = this.getDropItem(param1);
            if (_loc_2)
            {
                delete this._map[EntityUtil.toString(param1)];
            }
            return _loc_2;
        }// end function

        public function getDropItem(param1:SEntityId) : ItemPlayer
        {
            return this._map[EntityUtil.toString(param1)];
        }// end function

        public function get map() : Dictionary
        {
            return this._map;
        }// end function

        public function getDropItemByItemUnit(param1:int) : ItemPlayer
        {
            var _loc_2:ItemPlayer = null;
            for each (_loc_2 in this._map)
            {
                
                if (_loc_2.dropEntityInfo.unit == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getDropItemByItemCode(param1:int) : ItemPlayer
        {
            var _loc_2:ItemPlayer = null;
            var _loc_3:SPlayerItem = null;
            for each (_loc_2 in this._map)
            {
                
                _loc_3 = _loc_2.dropEntityInfo.playerItems[0] as SPlayerItem;
                if (_loc_3 == null)
                {
                    continue;
                }
                if (_loc_3.itemCode == param1)
                {
                    return _loc_2;
                }
            }
            return null;
        }// end function

        public function getEntityByRangle(param1:Rectangle = null, param2:Boolean = false) : Array
        {
            var _loc_4:ItemPlayer = null;
            if (!param1)
            {
                param1 = SceneRange.display;
            }
            var _loc_3:* = new Array();
            for each (_loc_4 in this._map)
            {
                
                if (param1.contains(_loc_4.x2d, _loc_4.y2d) && (!param2 || EntityUtil.isSelf(_loc_4.dropEntityInfo.ownerEntityId)))
                {
                    _loc_3.push(_loc_4);
                }
            }
            return _loc_3;
        }// end function

        public function getRandomDropItem(param1:Boolean = false) : ItemPlayer
        {
            var _loc_2:* = this.getEntityByRangle(SceneRange.display, param1);
            if (_loc_2.length == 0)
            {
                return null;
            }
            return _loc_2[MathUitl.random(0, (_loc_2.length - 1))];
        }// end function

        public function removeAll() : void
        {
            this._map = new Dictionary();
            return;
        }// end function

    }
}
